<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


use App\Http\Requests;
use App\Http\Controllers\Controller;

use DB;

class StuController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
	//显示主页面
    public function index()
    {
        $data = DB::table('auser')->orderBy('id','desc')->paginate(2);
        return view('admin.Index',['data'=>$data]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    //显示添加页面
    public function create()
    {
        return view("admin.add");
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
   		 $title = $request->title;
        $content = $request->content;
        $data = ['title'=>$title,'content'=>$content];
        $data = DB::table('auser')->insert($data);
        if($data){
            return redirect('/admin');
        }
        else{
            return back();
        }
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
       	 $data = DB::table("auser")->where("id",$id)->first();
         // $data->title = Markdown::convertToHtml(strip_tags($data->title));
         // $data->content = Markdown::convertToHtml(strip_tags($data->content));
         return view("admin.Show",['data'=>$data]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
    	$data = DB::table("auser")->where("id",$id)->first();
    	return view('admin.edit',['data'=>$data]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
       $res = ['title' => $request->title,'content' => $request->content];
       $data = DB::table("auser")->where("id",$id)->update($res);
       return redirect('/admin');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
       $data=DB::table('auser')->where('id',$id)->delete();
        return redirect('/admin');
    }
}
